package com.tanglongan.designPattern.dp19_state.demo99;

/**
 * 实现了不同状态之间可能存在自动切换的场景，但没有实现不同状态之间的自动切换
 */
public class GenericClient_1 {

    /**
     * 状态抽象
     */
    interface IState {
        void handle();
    }

    /**
     * 具体状态A
     */
    static class ConcreteStateA implements IState {
        @Override
        public void handle() {
            System.out.println("StateA do action");
        }
    }

    /**
     * 具体状态B
     */
    static class ConcreteStateB implements IState {
        @Override
        public void handle() {
            System.out.println("StateB do action");
        }
    }

    /**
     * 上下文环境
     */
    static class Context {
        private static final IState A = new ConcreteStateA();
        private static final IState B = new ConcreteStateB();
        //默认状态是A
        private IState currentState = A;

        public void setState(IState state) {
            this.currentState = state;
        }

        public void handle() {
            this.currentState.handle();
        }
    }

    public static void main(String[] args) {
        Context context = new Context();
        context.setState(new ConcreteStateB());
        context.handle();
    }
}
